﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using SetfNovelLib.Entities;
using SetfNovelLib;

namespace StefNovel
{
    public partial class ReadChapter : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["book"] == null)
                Session["book"] = TestStef.GenerateBook();
            BookInfo b = Session["book"] as BookInfo;
            if (Request["s"] != null)
            {
                int si = -1;
                if (int.TryParse(Request["s"].ToString(), out si))
                {
                    SectionType sec = (SectionType)si;
                    if (sec == SectionType.Developpement)
                    {
                        if (Request["c"] != null)
                        {
                            int ci = -1;
                            if (int.TryParse(Request["c"].ToString(), out ci))
                            {
                                WriteChapter(b.ContentChapters[ci]);
                            }
                            else
                                Server.Transfer("ReadBook.aspx");
                        }
                        else
                            Server.Transfer("ReadBook.aspx");
                    }
                    else if( b.SpecialSections.ContainsKey(sec))
                    {
                        WriteChapter(b.SpecialSections[sec]);
                    }
                    else
                        Server.Transfer("ReadBook.aspx");
                }
                else
                    Server.Transfer("ReadBook.aspx");
            }
            else
                Server.Transfer("ReadBook.aspx");
        }
        private void WriteChapter(ChapterInfo c)
        {
            lblTitle.Text = c.Title;
            litContent.Text = c.Content.Replace("\n", "<br />");
        }
    }
}